{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import scipy.special\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "class NeuralNetwork:\n",
    "    # initialise the neural network\n",
    "    def __init__(self, input_nodes, hidden_nodes, output_nodes, learning_rate) -> None:\n",
    "        self.inodes = input_nodes\n",
    "        self.hnodes = hidden_nodes\n",
    "        self.onodes = output_nodes\n",
    "        self.lr = learning_rate\n",
    "\n",
    "        # set weight: input -> hidden, -0.5 ~ +0.5\n",
    "        # self.wih = np.random.rand(self.hnodes, self.inodes) - 0.5\n",
    "        self.wih = np.random.normal(0.0, pow(self.hnodes, -0.5), (self.hnodes, self.inodes))\n",
    "        # hidden -> output\n",
    "        # self.who = np.random.rand(self.onode, self.hnodes) - 0.5\n",
    "        self.who = np.random.normal(0.0, pow(self.onodes, -0.5), (self.onodes, self.hnodes))\n",
    "\n",
    "        # activation function: sigmoid = 1/(1+exp(-x))\n",
    "        self.activation_function = lambda x: scipy.special.expit(x)\n",
    "\n",
    "    # train the neural network\n",
    "    def train(self, input_list, target_list):\n",
    "        inputs = np.array(input_list, ndmin=2).T\n",
    "        targets = np.array(target_list, ndmin=2).T\n",
    "        hidden_inputs = np.dot(self.wih, inputs)\n",
    "        hidden_outputs = self.activation_function(hidden_inputs)\n",
    "        final_inputs = np.dot(self.who, hidden_outputs)\n",
    "        final_outputs = self.activation_function(final_inputs)\n",
    "\n",
    "        # calculate errors\n",
    "        output_errors = targets - final_outputs\n",
    "        hidden_errors = np.dot(self.who.T, output_errors)\n",
    "\n",
    "        # update weights\n",
    "        self.who += self.lr * np.dot(output_errors * final_outputs * (1.0 - final_outputs), np.transpose(hidden_outputs))\n",
    "        self.wih += self.lr * np.dot(hidden_errors * hidden_outputs * (1.0 - hidden_outputs), np.transpose(inputs))\n",
    "\n",
    "    # query the neural network\n",
    "    def query(self, input_list):\n",
    "        # convert input to 2d array\n",
    "        inputs = np.array(input_list, ndmin=2).T\n",
    "        hidden_inputs = np.dot(self.wih, inputs)\n",
    "        hidden_outputs = self.activation_function(hidden_inputs)\n",
    "        final_inputs = np.dot(self.who, hidden_outputs)\n",
    "        final_outputs = self.activation_function(final_inputs)\n",
    "        return final_outputs\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "training_data_file = open('mnist_dataset/mnist_train.csv', 'r')\n",
    "training_data_list = training_data_file.readlines()\n",
    "training_data_file.close()\n",
    "# test results\n",
    "test_data_file = open('mnist_dataset/mnist_test.csv', 'r')\n",
    "test_data_list = test_data_file.readlines()\n",
    "test_data_file.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def do_train_and_test(model, output_nodes, learning_rate, correct_rates, epochs):\n",
    "    for epoch in range(epochs):\n",
    "        for record in training_data_list:\n",
    "            all_values = record.split(',')\n",
    "            inputs = np.asfarray(all_values[1:]) / 255.0 * 0.99 + 0.01\n",
    "            targets = np.zeros(output_nodes) + 0.01\n",
    "            targets[int(all_values[0])] = 0.99\n",
    "            model.train(inputs, targets)\n",
    "\n",
    "    # record scores\n",
    "    score_card = []\n",
    "    num_score = {0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}\n",
    "    num_total = {0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}\n",
    "    for record in test_data_list:\n",
    "        all_values = record.split(',')\n",
    "        correct_label = int(all_values[0])\n",
    "        num_total[correct_label] += 1\n",
    "        inputs = np.asfarray(all_values[1:]) / 255.0 * 0.99 + 0.01\n",
    "        outputs = model.query(inputs)\n",
    "        # get index of max value \n",
    "        label = np.argmax(outputs)\n",
    "        if label == correct_label:\n",
    "            score_card.append(1)\n",
    "            num_score[label] += 1\n",
    "        else:\n",
    "            score_card.append(0)\n",
    "    score_card_array = np.asarray(score_card)\n",
    "    correct_rates[learning_rate] = score_card_array.sum() / score_card_array.size\n",
    "    for key in num_total:\n",
    "        num_score[key] /= num_total[key]\n",
    "    return num_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 0.9877551020408163,\n",
       " 1: 0.9885462555066079,\n",
       " 2: 0.9593023255813954,\n",
       " 3: 0.9396039603960396,\n",
       " 4: 0.9704684317718941,\n",
       " 5: 0.9473094170403588,\n",
       " 6: 0.9707724425887265,\n",
       " 7: 0.9270428015564203,\n",
       " 8: 0.9517453798767967,\n",
       " 9: 0.9534192269573836}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# cost about \n",
    "epochs = 2\n",
    "learning_rate = 0.2\n",
    "input_nodes = 784 # image is 28 x 28\n",
    "hidden_nodes = 100\n",
    "output_nodes = 10 # 0 ~ 9 total 10 labels\n",
    "correct_rates = {}\n",
    "n = NeuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)\n",
    "num_score = do_train_and_test(n, output_nodes, learning_rate, correct_rates, epochs)\n",
    "num_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0.2: 0.9599}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "correct_rates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# recogonize customized numbers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x2722eaac490>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAOs0lEQVR4nO3df4gcdZrH8c9zcxFCDNFxxhiymuRUEDm9MQ7DwspGWRQNSLIqskEWD4JZQWGX5A9/BFxRgiKXXRY9lESjWbOXuP72D3PuGBfiIqwZ45xJlJxZTVzj6HSMGKOJuUye+2Mqy6hT357pru5q53m/YOjuerpSD4Ufq7u+Vf01dxeAie+fym4AQHMQdiAIwg4EQdiBIAg7EMQ/N3NjHR0dPnv27GZuEghl9+7d2rdvn41WqyvsZna5pN9JapP0sLvfm3r/7Nmz1dfXV88mASR0d3fn1mr+GG9mbZL+U9IVks6VtMjMzq313wPQWPV8Z++RtMvd33P3I5I2SFpQTFsAilZP2GdK+vuI1x9my77BzJaYWZ+Z9VUqlTo2B6AeDT8b7+6r3L3b3bs7OzsbvTkAOeoJ+15Jp494/YNsGYAWVE/Yt0g628zmmNkJkn4m6YVi2gJQtJqH3tz9qJndLOklDQ+9rXH3HYV1BqBQdY2zu/uLkl4sqBcADcTlskAQhB0IgrADQRB2IAjCDgRB2IEgmno/e1R796YvLLznnnuS9UcffTRZP/HEE3NrM2d+53aFbzjrrLOS9csuuyxZv+qqq5L19vb2ZB3Nw5EdCIKwA0EQdiAIwg4EQdiBIAg7EARDb01w3333JesPPvhgsn7s2LFk/auvvsqtDQ4OJtd98803k/WnnnoqWV+/fn2y/swzz+TWpk2bllwXxeLIDgRB2IEgCDsQBGEHgiDsQBCEHQiCsANBMM7eBOvWrUvWq42jl8ndk/VXXnklWb/yyitza88991xyXW6PLRZHdiAI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Q94k8uT1Qc2YEgCDsQBGEHgiDsQBCEHQiCsANBEHYgCHP35m3MrCJp5PzGHZL2Na2B8WnV3lq1L4nealVkb7PcfdTff2tq2L+zcbM+d+8urYGEVu2tVfuS6K1WzeqNj/FAEIQdCKLssK8qefsprdpbq/Yl0VutmtJbqd/ZATRP2Ud2AE1C2IEgSgm7mV1uZjvNbJeZ3VpGD3nMbLeZbTOzfjPrK7mXNWY2aGbbRyxrN7NeM3s3exx1jr2ServTzPZm+67fzOaX1NvpZvZnM3vbzHaY2S+z5aXuu0RfTdlvTf/ObmZtkv5X0qWSPpS0RdIid3+7qY3kMLPdkrrdvfQLMMzsx5IOSvq9u/9rtuw+Sfvd/d7sf5Qnu/stLdLbnZIOlj2NdzZb0YyR04xLWijp31Xivkv0da2asN/KOLL3SNrl7u+5+xFJGyTlTxsSmLtvlrT/W4sXSFqbPV+r4f9Ymi6nt5bg7gPuvjV7/oWk49OMl7rvEn01RRlhnynp7yNef6jWmu/dJf3JzN4wsyVlNzOK6e5+fL6pjyVNL7OZUVSdxruZvjXNeMvsu1qmP68XJ+i+6yJ3nyvpCkk3ZR9XW5IPfwdrpbHTMU3j3SyjTDP+D2Xuu1qnP69XGWHfK+n0Ea9/kC1rCe6+N3sclPSsWm8q6k+Oz6CbPQ6W3M8/tNI03qNNM64W2HdlTn9eRti3SDrbzOaY2QmSfibphRL6+A4zm5KdOJGZTZF0mVpvKuoXJF2fPb9e0vMl9vINrTKNd9404yp535U+/bm7N/1P0nwNn5H/m6TlZfSQ09e/SPqf7G9H2b1JWq/hj3X/p+FzG4slnSJpk6R3Jb0sqb2Fentc0jZJb2k4WDNK6u0iDX9Ef0tSf/Y3v+x9l+irKfuNy2WBIDhBBwRB2IEgCDsQBGEHgiDsQBCEHQiCsANB/D/UUXEigcyDdwAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img = cv2.imread('images/3-2.png', cv2.IMREAD_GRAYSCALE)\n",
    "img_data = (255.0 - img.reshape(28, 28)) / 255.0 * 0.99 + 0.01\n",
    "predicts = n.query(img_data.flatten())\n",
    "print(np.argmax(predicts))\n",
    "plt.imshow(img_data, cmap='Greys', interpolation='None')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1.13527242e-02]\n",
      " [2.46264049e-06]\n",
      " [4.20083814e-03]\n",
      " [1.01520015e-04]\n",
      " [9.55572198e-03]\n",
      " [5.18538529e-04]\n",
      " [1.25937211e-02]\n",
      " [2.92026104e-06]\n",
      " [1.62113322e-02]\n",
      " [1.05157205e-01]]\n"
     ]
    }
   ],
   "source": [
    "print(predicts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x2722e98d340>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAL70lEQVR4nO3dX6gc9RnG8efx1BAwIrFZQjChSUQQKTTKEguKWKQShRD1QsxFSUEaLxQMeFGxoOKVlGpQEOFYgyfFKoKKuQitNgjijbqGU42G1n8RE2KyQY3mxmh8e3FGe4xnZ092ZndW3+8Hlp2dd/bMy5Anszu/3f05IgTgp++0phsAMBqEHUiCsANJEHYgCcIOJPGzUe5syZIlsXLlylHuEkhl3759OnLkiOeqVQq77XWSHpA0IemvEXFv2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B2TtD0iflms+7OkTyLi3uI/ysUR8ccx6e1uSceansa7mK1o2expxiVdI+n3avDYlfR1vUZw3Jo4s6+V9G5EvB8RxyU9KWlDA32MvYh4SdInJ63eIGmqWJ7SzD+WkevR21iIiIMRsbtY/kLSt9OMN3rsSvoaiSbCfo6kj2Y93q/xmu89JD1v+3Xbm5tuZg5LI+JgsfyxpKVNNjOHvtN4j9JJ04yPzbEbZPrzqrhA90OXRsRFkq6SdHPxcnUsxcx7sHEaO53XNN6jMsc0499p8tgNOv15VU2E/YCkFbMeLy/WjYWIOFDcH5b0rMZvKupD386gW9wfbrif74zTNN5zTTOuMTh2TU5/3kTYX5N0nu1VthdIukHSjgb6+AHbZxQXTmT7DElXavymot4haVOxvEnScw328j3jMo13r2nG1fCxa3z684gY+U3S1Zq5Iv+epD810UOPvlZL+ndxe6vp3iQ9oZmXdV9p5trGjZJ+LmmXpHck/UvS2WPU298kvSnpDc0Ea1lDvV2qmZfob0iaLm5XN33sSvoayXHj47JAElygA5Ig7EAShB1IgrADSRB2IAnCDiRB2IEk/gcfiaQoWwWEqwAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "data_file = open('mnist_dataset/mnist_train_100.csv', 'r')\n",
    "data_list = data_file.readlines()\n",
    "data_file.close()\n",
    "all_values = data_list[8].split(',')\n",
    "image_array = np.asfarray(all_values[1:])\n",
    "print(all_values[0], np.argmax(n.query(image_array)))\n",
    "plt.imshow(image_array.reshape(28, 28), cmap='Greys', interpolation='None')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.13 ('ai')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "0cb0046d74bfb5a9fee6ebb85b9850d762e40d6b321d5d9a0aa0313eefa3c5b4"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
